package com.zh.config;

import com.zh.plus.AccessInterceptor;
import com.zh.plus.AdminAccessInterceptor;
import com.zh.plus.UserArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Autowired
    UserArgumentResolver userArgumentResolver;

    @Autowired
    AccessInterceptor accessInterceptor;

    @Autowired
    AdminAccessInterceptor adminAccessInterceptor;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(userArgumentResolver);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 用户拦截器
        InterceptorRegistration ir = registry.addInterceptor(accessInterceptor);
        // 配置拦截的路径
        ir.addPathPatterns("/user/**");
        ir.addPathPatterns("/auth/**");
        ir.addPathPatterns("/admin/**");
        ir.addPathPatterns("/queryLog/**");

        // 用户管理拦截器
        registry.addInterceptor(adminAccessInterceptor).addPathPatterns("/admin/**");



    }
}
